﻿using Autofac.Extras.DynamicProxy;
using Infrastructure.Repositories;
using Infrastructure.UnitWork;
using TestDDD.CustomAttribute;
using TestDDD.Interceptors;

namespace TestDDD.Services
{
    public class BaseService<TEntity>(IRepository<TEntity> repository, IUnitOfWork unitOfWork) : IBaseService<TEntity> where TEntity : class, new()
    {
        public async Task<TEntity> AddAsync(TEntity entity)
        {
            TEntity e = await repository.InsertReturnEntityAsync(entity);
            return e;
        }

        public TEntity Add(TEntity entity)
        {
            TEntity e = repository.InsertReturnEntity(entity);
            return e;
        }

        public async Task<bool> Update(TEntity entity)
          => await repository.UpdateAsync(entity);
    }
}
